package com.gx.smart.building.ui.repair.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import com.gx.smart.base.BaseAdapter;
import com.gx.smart.building.R;
import com.gx.smart.building.databinding.ItemSelectSpareBinding;
import com.gx.smart.building.ui.repair.SelectSparePartActivity;
import com.huishi.gx.ib.grpc.lib.ib.asset.spare.v1.dto.SpareDto;

import java.util.Map;

/**
 * @author: xiaosy
 * 时间: 2022/4/25
 * @Description: java类作用描述
 * @Version: 1.0
 **/
public class SelectSpareAdapter extends BaseAdapter<SpareDto, SelectSpareAdapter.ViewHolder> {
    public SelectSpareAdapter(Context context) {
        super(context);
    }

    @Override
    protected int onBindLayout() {
        return R.layout.item_select_spare;
    }

    @Override
    protected ViewHolder onCreateHolder(View view) {
        ItemSelectSpareBinding binding = ItemSelectSpareBinding.inflate(LayoutInflater.from(mContext),
                (ViewGroup) view, false);
        return new ViewHolder(binding);
    }

    @Override
    protected void onBindData(ViewHolder holder, SpareDto item, int position) {
        Map<Integer, Integer> positionList = ((SelectSparePartActivity) mContext).getPositionList();
        holder.binding.spareName.setText(item.getSpareName() + " (" + item.getModel() + ")");
        if (positionList != null
                && !positionList.isEmpty()
                && positionList.values().contains(position)) {
            holder.binding.select.setText("已选择");
        } else {
            holder.binding.select.setText("选择");
        }
    }

    protected static class ViewHolder extends RecyclerView.ViewHolder {
        private final ItemSelectSpareBinding binding;

        public ViewHolder(ItemSelectSpareBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }
}
